package com.onenine.app.view;

import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.SharedElementCallback;
import android.support.v4.view.ViewCompat;
import android.view.View;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 动画元素Helper
 */
public class TransitionViewHelper {

    /**
     * 视图共享元素的View处理
     *
     * @param activity
     * @param exitView
     */
    public static void onActivityReenter(FragmentActivity activity, View exitView) {
        if (activity == null) {
            return;
        }
        if (exitView == null) {
            return;
        }
        ActivityCompat.setExitSharedElementCallback(activity, new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
                names.clear();
                sharedElements.clear();
                names.add(ViewCompat.getTransitionName(exitView));
                sharedElements.put(Objects.requireNonNull(ViewCompat.getTransitionName(exitView)), exitView);
                activity.setExitSharedElementCallback(new SharedElementCallback() {
                });
            }
        });
    }

}
